package com.umeox.watch.moto.contact.base;

import android.content.Context;
import android.net.Uri;

import com.dbflow5.annotation.Database;
import com.dbflow5.config.DBFlowDatabase;
import com.dbflow5.config.DatabaseConfig;
import com.dbflow5.config.FlowConfig;
import com.dbflow5.config.FlowManager;
import com.dbflow5.contentprovider.annotation.ContentProvider;
import com.dbflow5.database.AndroidSQLiteOpenHelper;
import com.umeox.watch.moto.dataservice.DataProvider;

@Database(version = BaseDatabase.VERSION)
@ContentProvider(authority = BaseDatabase.AUTHORITY,
        database = BaseDatabase.class,
        baseContentUri = BaseDatabase.BASE_CONTENT_URI)
public abstract class BaseDatabase extends DBFlowDatabase {
    //数据库名称
    public static final String NAME = "video_call";
    //数据库版本号
    public static final int VERSION = 1;

    public static final String AUTHORITY = DataProvider.VideoCallProvider.AUTHORITY;

    public static final String BASE_CONTENT_URI = "content://";

    public static void setup(Context context) {
        FlowManager.init(new FlowConfig.Builder(context)
                .database(DatabaseConfig.builder(BaseDatabase.class, AndroidSQLiteOpenHelper.createHelperCreator(context))
                        .databaseName(NAME)
                        .build())
                .build());
    }

    public static Uri buildUri(String... paths) {
        Uri.Builder builder = Uri.parse(BASE_CONTENT_URI + AUTHORITY).buildUpon();
        for (String path : paths) {
            builder.appendPath(path);
        }
        return builder.build();
    }

    public static DBFlowDatabase getDatabase() {
        return FlowManager.getDatabase(BaseDatabase.class);
    }
}
